﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using agvcontroller.Log;

namespace agvcontroller.GUI
{
    /// <summary>
    /// Interaction logic for Toast.xaml
    /// </summary>
    public partial class Toast : Window
    {
        Logger Log;

        private string Msg;
        public Toast(Window _owner , int _interval = 2)
        {
            InitializeComponent();

            Log = new Logger("Toast");

            Owner = _owner;

            RegisterName("Toast", this);

            tmr.Interval = new TimeSpan(0,0,_interval);
            tmr.Tick += new EventHandler(tmr_Tick);
        }

         private void lbMsg_Loaded(object sender, RoutedEventArgs e)
        {
        }

        /// <summary>
        /// show toast with message.
        /// </summary>
        /// <param name="_msg"></param>
         public void ShowMsg(string _msg)
         {
             tmr.Start();
             lbMsg.Content = _msg;

             Show();
         }

        /// <summary>
        /// Timer for toast show time 
        /// </summary>
        System.Windows.Threading.DispatcherTimer tmr = new System.Windows.Threading.DispatcherTimer();

        void tmr_Tick(object sender, EventArgs e)
        {
            FormFadeOut.Begin();
        }

        /// <summary>
        /// disappear toast 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Toast_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
        }

        /// <summary>
        /// fade out event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormFadeOut_Completed(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
